<?php
namespace My;
class Mail{
	private $_options;

	static function sendMail($arrData){
		$options = \Zend_Registry::get('config');
		$is_smtp = $options['mail']['issmtp'];
		if ($is_smtp == FALSE) {
			$tr = new \Zend_Mail_Transport_Sendmail('-freturn_to_noreply@vinabroker.vn');
		} else {
			//var_dump($options["mail"]["pass"]); die();
			$config = array(
					"ssl"	=> 'ssl',
					"port"	=> 465,
					'auth' => 'login' ,
					'username' => $options["mail"]["name"],
					'password' => $options["mail"]["pass"]
			);
			$tr = new \Zend_Mail_Transport_Smtp( $options['mail']['smtphost'] , $config);
		}
		 
		\Zend_Mail::setDefaultTransport($tr);
		$mail = new \Zend_Mail("UTF-8");
		$mail->setBodyHtml($arrData["content"]);
		$mail->setFrom($arrData["fromMail"], $arrData["fromName"]);
		$mail->addTo($arrData["toMail"], $arrData["toName"]);
		$mail->setSubject($arrData["subject"]);
		 
		if (array_key_exists("attach", $arrData)) {
			$at = $mail->createAttachment($arrData["attach"]["data"]);
			$at->type = $arrData["attach"]["type"];
			$at->filename = $arrData["attach"]["filename"];
		}
		 
		try {
			$mail->send();
			return true;
		} catch (\Exception $e) {
			//echo $e->getMessage();
			return false;
		}
	}
}
?>